<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:76:"E:\wamp\wamp\www\s72\xingjian\public/../application/admin\view\user\add.html";i:1524985464;}*/ ?>

<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
    </script>

    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            <a href="<?php echo url('admin/index/index'); ?>">首页</a>
        </li>

        <li>
           用户管理
        </li>
        <li class="active">添加用户</li>
    </ul><!-- .breadcrumb -->

</div>
<div class="container" style="margin-top: 30px;">
<div class="row">
    <div class="col-xs-12">
        <!-- PAGE CONTENT BEGINS -->

        <form class="form-horizontal" id="add-form"  role="form">
            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="username"> 用户名： </label>

                <div class="col-sm-9">
                    <input type="text" id="username" placeholder="用户名" onblur="reName();" name="username" class="col-xs-10 col-sm-5" />
                    <span class="help-inline col-xs-12 col-sm-7">
                        <span class="middle"></span>
                    </span>
                </div>
            </div>

            <div class="space-4"></div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="email"> 邮箱： </label>

                <div class="col-sm-9">
                    <input type="text" id="email" placeholder="邮箱" onblur="reEmail();" name="email" class="col-xs-10 col-sm-5" />
                    <span class="help-inline col-xs-12 col-sm-7">
                        <span class="middle"></span>
                    </span>
                </div>
            </div>

            <div class="space-4"></div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="tel"> 手机号： </label>
                <div class="col-sm-9">
                    <input type="text" id="tel" placeholder="手机号" onblur="reTel();"  name="tel" class="col-xs-10 col-sm-5" />
                    <span class="help-inline col-xs-12 col-sm-7">
                        <span class="middle"></span>
                    </span>
                </div>
            </div>

            <div class="space-4"></div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right" for="password"> 密码： </label>
                <div class="col-sm-9">
                    <input type="password" id="password" placeholder="密码" onblur="rePass();" name="password" class="col-xs-10 col-sm-5" />
                    <span class="help-inline col-xs-12 col-sm-7">
                        <span class="middle"></span>
                    </span>
                </div>
            </div>

            <div class="space-4"></div>

            <div class="form-group">
                <label class="col-sm-3 control-label no-padding-right"> 状态： </label>
                <div class="col-sm-9">
                    <label>启用：<input  type="radio"  checked  name="status" value="1"/></label>
                    <label style="margin-left: 20px;">禁用：<input  type="radio"  name="status" value="0" /></label>
                </div>
            </div>

            <div class="form-group">
                <div class="control-group">
                    <label class="col-sm-3 control-label no-padding-right"> 分配角色： </label>
                    <div class="col-sm-9">
                        <?php if(is_array($data) || $data instanceof \think\Collection || $data instanceof \think\Paginator): $i = 0; $__LIST__ = $data;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$info): $mod = ($i % 2 );++$i;?>
                        <label style="margin: 0 5px;">
                        <span class="lbl"><?php echo $info['name']; ?></span>
                        <input name="role[]" value="<?php echo $info['id']; ?>" type="checkbox" />
                        </label>
                        <?php endforeach; endif; else: echo "" ;endif; ?>
                    </div>
                </div>
            </div>


            <div class="clearfix">
                <div class="col-md-offset-3 col-md-9">
                    <button class="btn btn-info btn-doadd" type="button">
                        <i class="icon-ok bigger-110"></i>
                        提交
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
        <script>

            $(function(){
                $('#username').focus();
            });


            function reName(){
                var username = $('#username').val();
                if(!/^([a-zA-Z0-9\u4e00-\u9fa5\·]{1,10})$/.test(username)){
                     $('.middle').eq(0).html('不能包含特殊符号。1到10字符').css({'color': 'red'});
                    return false;
                }else{
                    $('.middle').eq(0).html('正确').css({'color': 'green'});
                    return true;
                }
            }

            function reEmail(){
                var email = $('#email').val();
                if(!/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email)){
                    $('.middle').eq(1).html('邮箱的基本格式为“名称@域名”').css({'color': 'red'});
                    return false;
                }else{
                    $('.middle').eq(1).html('正确').css({'color': 'green'});
                    return true;
                }
            }

            function reTel(){
                var tel = $('#tel').val();
                if(!/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(tel)){
                    $('.middle').eq(2).html('请输入有效的手机号码！').css({'color': 'red'});
                    return false;
                }else{
                    $('.middle').eq(2).html('正确').css({'color': 'green'});
                    return true;
                }
            }
            function rePass(){
                var password = $('#password').val();
                if(!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,21}$/.test(password)){
                    $('.middle').eq(3).html('只能是6-21个字母、数字组合而成').css({'color': 'red'});
                    return false;
                }else{
                    $('.middle').eq(3).html('正确').css({'color': 'green'});
                    return true;
                }
            }

            $('.btn-doadd').click(function(){
                 if(reName() && reEmail() && reTel() && rePass()){
                    var info = $('#add-form input').serialize();
                    $.ajax({
                        type : 'post',
                        data : info,
                        url : "<?php echo url('admin/users/save'); ?>",
                        success : function(data){
                            if(data.status){
                                alert('添加成功');
                                $('#showuser').click();
                            }else{
                                alert('添加失败');
                            }
                        },
                        error : function(){
                            alert('请求失败');
                        }
                    });
                }else{
                    alert('验证不通过');
                }

            });


        </script>









